<template>
  <el-dialog
    title="充值账号信息添加"
    :visible.sync="dialog_visible"
    width="70%"
    height="80%"
  >
    <div class="form-padding">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="temp"
        label-position="right"
        auto-complete="on"
        label-width="120px"
        style="width: 100%"
      >
        <el-form-item label="序号" prop="ID">
          <el-input
            disabled
            style="width: 100%"
            placeholder="新增无需序号"
            v-model="temp.ID"
          />
        </el-form-item>
        <el-form-item label="充值日期" prop="Rehcarge_Time">
          <el-date-picker
            style="width: 100%"
            v-model="temp.Rehcarge_Time"
            type="date"
            placeholder="请输入充值日期"
          />
        </el-form-item>
        <el-form-item label="游戏名" prop="Game">
          <el-input
            placeholder="请输入游戏名"
            style="width: 100%"
            v-model="temp.Game"
          />
        </el-form-item>
        <el-form-item label="游戏端口" prop="Chan">
          <el-input
            placeholder="请输入游戏端口"
            style="width: 100%"
            v-model="temp.Chan"
          />
        </el-form-item>
        <el-form-item label="账号" prop="Account">
          <el-input
            placeholder="请输入账号"
            style="width: 100%"
            v-model="temp.Account"
          />
        </el-form-item>
        <el-form-item label="开号折扣点位" prop="Discount">
          <el-input
            placeholder="请输入开号折扣点位"
            style="width: 100%"
            v-model="temp.Discount"
          />
        </el-form-item>
        <el-form-item label="游戏币名称" prop="PayUse">
          <el-input
            placeholder="请输入游戏币名称"
            style="width: 100%"
            v-model="temp.PayUse"
          />
        </el-form-item>
        <el-form-item label="开号金额" prop="Money">
          <el-input
            placeholder="请输入开号金额"
            style="width: 100%"
            v-model="temp.Money"
          />
        </el-form-item>
        <el-form-item label="余额" prop="Residue">
          <el-input
            placeholder="请输入余额"
            style="width: 100%"
            v-model="temp.Residue"
          />
        </el-form-item>
        <el-form-item label="账号来源" prop="source">
          <el-input
            placeholder="请输入账号来源"
            style="width: 100%"
            v-model="temp.source"
          />
        </el-form-item>
        <el-form-item label="店铺名字" prop="Store">
          <el-input
            placeholder="请输入店铺名字"
            style="width: 100%"
            v-model="temp.Store"
          />
        </el-form-item>
        <el-form-item label="手机号" prop="Phone">
          <el-input
            placeholder="请输入手机号"
            style="width: 100%"
            v-model="temp.Phone"
          />
        </el-form-item>
        <el-form-item label="手机型号" prop="device">
          <el-input
            placeholder="请输入手机型号"
            style="width: 100%"
            v-model="temp.device"
          />
        </el-form-item>
        <el-form-item label="地区" prop="Area">
          <el-input
            placeholder="请输入地区"
            style="width: 100%"
            v-model="temp.Area"
          />
        </el-form-item>
        <el-form-item label="手机设备码" prop="Imei">
          <el-input
            placeholder="请输入手机设备码"
            style="width: 100%"
            v-model="temp.Imei"
          />
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="submit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { notExistAdd} from "@/api/recharge_accout";
import g from "@/utils/utilFn";


export default {
  name: "accountAdd",
  components: {  },
  props: {
    show: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    const validaterole_name = (rule, value, callback) => {
      if (value.length > 30) {
        callback(new Error("名称不能太长！"));
      } else {
        callback();
      }
    };
    return { 
      temp: {
        ID: "",
        Game: "",
        Chan: "",
        Account: "",
        Discount: "",
        PayUse: "",
        Money: "",
        Residue: "",
        source: "",
        Store: "",
        Phone: "",
        device: "",
        Area: "",
        Imei: "",
        Rehcarge_Time: "",
      },
      rules: {
        Account: [
          { required: true, message: "充值账号不能为空", trigger: "blur" },
        ],
        Rehcarge_Time: [
          {
            required: true,
            message: "充值日期不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {
    dialog_visible: {
      get() {
        return this.show;
      },
      set(val) {
        this.$emit("update:show", val);
      },
    },
  },
  created() {  
  },
  watch: {
    dialog_visible(newValue, oldValue) {
      if (newValue) {
      
      }
    },
  },
  methods: {
    cancel() {
      this.dialog_visible = false;
    },
    submit() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
        const param = {
            ID: this.temp.ID,
            Rehcarge_Time: g.format(this.temp.Rehcarge_Time, "yyyy-MM-dd"),
            Game: this.temp.Game,
            Chan: this.temp.Chan,
            Account: this.temp.Account,
            Discount: this.temp.Discount,
            PayUse: this.temp.PayUse,
            Money: this.temp.Money,
            Residue: this.temp.Residue,
            source: this.temp.source,
            Store: this.temp.Store,
            Phone: this.temp.Phone,
            device: this.temp.device,
            Area: this.temp.Area,
            Imei: this.temp.Imei,
          };
          notExistAdd(param).then((response) => {
            if (response.data > 0) {
              setTimeout(() => {
                this.dialog_visible = false;
                this.$message({
                  type: "success",
                  message: "充值账号信息添加成功!",
                });
                this.$refs["dataForm"].resetFields();
                this.$emit("success", param);
              }, 200);
            } else {
              this.$message({
                type: "info",
                message: "充值账号信息添加失败,充值账号不能重复",
              });
            }
          });
        }
      });
    },
  },
};
</script>